﻿using Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ViewModels.Career;

namespace ProdService
{
    public class CareerService : BaseService
    {
        public CareerService(DbContext dbContext, IHttpContextAccessor accessor)
            : base(dbContext, accessor)
        {

        }

        public NeedHelpListModel GetList()
        {
            var lst = dbContext.Set<Career>().ToList();
            NeedHelpListModel model = new NeedHelpListModel
            {
                Items = mapper.Map<IList<_NeedHelpItemModel>>
                (lst),
            };
            return model;
        }

        public int NeedHelp(NeedHelpModel model)
        {
            Career career = mapper.Map<Career>(model);
            career.User = GetCurrentUser();
            career.Offer = model.Offer;
            dbContext.Add(career);
            dbContext.SaveChanges();
            return career.Id;
        }

    }
}
